﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using System.Data.SqlClient;
using System.Data;

namespace Jxym.wlkc2011.Module.Default.server.DbBack
{
    public partial class dbBack_Revert : System.Web.UI.Page
    {
        private string fromBackPath = "";
        private string fromFileName = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string returnStr = "0";
                if (Request.Params["fromBackPath"] != null) fromBackPath = Request.Params["fromBackPath"];
                if (Request.Params["fromFileName"] != null) fromFileName = Request.Params["fromFileName"];

                if (fromBackPath != "" && fromFileName != "")
                {
                    string path = fromBackPath + fromFileName;
                    SqlConnection conn = new SqlConnection(Jxym.DBUtility.JxymSqlHelper.ConnectionStringInventoryDistributedTransaction);
                    conn.Open();

                    SqlCommand cmdRT = new SqlCommand();
                    cmdRT.CommandType = CommandType.Text;
                    cmdRT.Connection = conn;
                    cmdRT.CommandText = @"restore database AIMS from disk='" + path + "'";

                    try
                    {
                        cmdRT.ExecuteNonQuery();
                        returnStr = "1";
                    }
                    catch (Exception ex)
                    {
                        returnStr = ex.Message;
                    }
                    finally
                    {
                        conn.Close();
                        conn.Dispose();
                    }
                }
                Response.Write(returnStr);
            }
        }
    }
}